// 验证单个概率值是否合法
function validateProbability(prob) {
  if (isNaN(prob)) {
      return { isValid: false, message: "请输入数字！" };
  } else if (prob <= 0) {
      return { isValid: false, message: "请输入大于0的数" };
  } else if (prob >= 1) {
      return { isValid: false, message: "请输入小于1的数" };
  }
  return { isValid: true };
}

// 验证整个概率数组是否满足概率和为1的要求
function validateProbabilitiesSum(probabilities) {
  const sum = probabilities.reduce((acc, prob) => acc + prob, 0);
  if (sum > 1) {
      return { isValid: false, message: "概率空间不封闭，概率和大于1！" };
  } else if (sum < 1) {
      return { isValid: false, message: "概率空间不封闭，概率和小于1！" };
  }
  return { isValid: true };
}

module.exports = { validateProbability, validateProbabilitiesSum };

